package com.ccp.dev.workflow.model;

import com.ccp.dev.core.basic.model.BaseModel;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import java.util.Date;

public class ProcessRun extends BaseModel<ProcessRun> implements Cloneable {
    /**
     * 挂起状态
     */
    public static final Short STATUS_SUSPEND = 0;
    /**
     * 运行状态
     */
    public static final Short STATUS_RUNNING = 1;
    /**
     * 结束状态
     */
    public static final Short STATUS_FINISH = 2;
    /**
     * 人工终止
     */
    public static final Short STATUS_MANUAL_FINISH = 3;
    /**
     * 草稿状态
     */
    public static final Short STATUS_FORM = 4;
    /**
     * 已撤销
     */
    public static final Short STATUS_RECOVER = 5;
    /**
     * 已驳回
     */
    public static final Short STATUS_REJECT = 6;
    /**
     * 已追回
     */
    public static final Short STATUS_REDO = 7;
    /**
     * 逻辑删除
     */
    public static final Short STATUS_DELETE = 10;


    /**
     * 试运行
     */
    public static final Short TEST_RUNNING = 0;
    /**
     * 正常运行
     */
    public static final Short FORMAL_RUNNING = 1;
    /**
     * 不追回
     */
    public static final Short RECOVER_NO = 0;
    /**
     * 追回
     */
    public static final Short RECOVER = 1;


    /**
     * 主键
     */
    private String runId;
    /**
     * 流程模型Id
     */
    private String modelId;
    /**
     * 流程实例标题
     */
    private String subject;
    /**
     * 创建人ID
     */
    private String creatorId;
    /**
     * 创建人
     */
    private String creator;
    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 业务表单简述
     */
    private String busDescp;
    /**
     * 状态
     */
    private Short status;
    /**
     * flowable流程实例ID
     */
    private String procInstId;
    /**
     * flowable流程定义ID
     */
    private String procDefId;
    /**
     * 关联的表单的业务主键
     */
    private String businessKey;
    /**
     * 关联的表单主键为Long
     */
    private Long businessKeyNum = 0L;
    /**
     * businessUrl
     */
    private String businessUrl;
    /**
     * 结束时间
     */
    private Date endTime;
    /**
     * 执行持续时间总长（毫秒)
     */
    private Long duration;
    /**
     * 流程定义名称
     */
    private String processName;
    /**
     * 主键名称
     */
    private String pkName = "";
    /**
     * 表名
     */
    private String tableName = "";
    /**
     * 父流程运行的ID
     */
    private String parentId;
    /**
     * 发起人所在组织名称
     */
    private String startOrgName = "";
    /**
     * 发起人所在组织Id
     */
    private String startOrgId = "";
    /**
     * 追回状态
     */
    private Short recover = RECOVER_NO;
    /**
     * 表单定义
     */
    private String formDefId = "";
    /**
     * 数据源
     */
    private String dsAlias;

    /**
     * 表单Key或Url
     */
    private String formKeyUrl;
    /**
     * 表单类型
     */
    private Short formType;
    /**
     * 权限等级。
     * 1.标题;2.显示流程实例信息;3.可以干预
     */
    private Short grade = 1;
    /**
     * 基于最后一次提交，执行持续时间总长（毫秒)
     */
    private Long lastSubmitDuration;

    private String typeId;

    private String typeName;

    private String tagIds;

    /**
     * 组织名称
     */
    private String orgName;

    /**
     * 是否允许回退到发起人，不对应数据库字段。
     */
    private boolean allowBackToStart = false;

    //是否允许我的办结转发
    private Integer allowFinishedDivert = 1;

    private String copyId;

    private String flowKey = "";

    private String startNode = "";

    /**
     * 是否正式流程实例
     * 1：正式
     * 0：测试数据
     */
    private Short isFormal = 1;

    /**
     * 流程实例归档后是否允许打印表单
     */
    private Short isPrintForm = 0;

    /**
     * 关联ID。
     */
    private String relRunId;


    /**
     * 对应流程分管授权的实例权限分配
     */
    private AuthorizeRight authorizeRight;

    /**
     * 全局流水号
     */
    private String globalFlowNo;

    /**
     * 任务ID
     */
    private String taskId;
    /**
     * 任务名称
     */
    private String taskName;

    private String assignee;

    /**
     * 当前节点审批节点是否是第一个节点
     */
    private boolean currentNodeIsFirst;

    public boolean isCurrentNodeIsFirst() {
        return currentNodeIsFirst;
    }

    public void setCurrentNodeIsFirst(boolean currentNodeIsFirst) {
        this.currentNodeIsFirst = currentNodeIsFirst;
    }

    public String getCopyId() {
        return copyId;
    }

    public void setCopyId(String copyId) {
        this.copyId = copyId;
    }

    public String getTypeId() {
        return typeId;
    }

    public void setTypeId(String typeId) {
        this.typeId = typeId;
    }

    public void setRunId(String runId) {
        this.runId = runId;
    }


    public String getAssignee() {
        return assignee;
    }

    public void setAssignee(String assignee) {
        this.assignee = assignee;
    }

    /**
     * 返回 runId
     *
     * @return
     */
    public String getRunId() {
        return runId;
    }

    public void setModelId(String modelId) {
        this.modelId = modelId;
    }

    public String getFormDefId() {
        return formDefId;
    }

    public void setFormDefId(String formDefId) {
        this.formDefId = formDefId;
    }

    /**
     * 返回 流程定义ID
     *
     * @return
     */
    public String getModelId() {
        return modelId;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    /**
     * 返回 流程实例标题
     *
     * @return
     */
    public String getSubject() {
        return subject;
    }

    public void setCreatorId(String creatorId) {
        this.creatorId = creatorId;
    }

    /**
     * 返回 创建人ID
     *
     * @return
     */
    public String getCreatorId() {
        return creatorId;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public Short getGrade() {
        return grade;
    }

    public void setGrade(Short grade) {
        this.grade = grade;
    }

    /**
     * 返回 创建人
     *
     * @return
     */
    public String getCreator() {
        return creator;
    }

    @Override
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    /**
     * 返回 创建时间
     *
     * @return
     */
    @Override
    public Date getCreateTime() {
        return createTime;
    }

    public void setBusDescp(String busDescp) {
        this.busDescp = busDescp;
    }

    /**
     * 返回 业务表单简述
     *
     * @return
     */
    public String getBusDescp() {
        return busDescp;
    }

    public void setStatus(Short status) {
        this.status = status;
    }

    /**
     * 返回 状态
     *
     * @return
     */
    public Short getStatus() {
        return status;
    }

    public void setProcInstId(String procInstId) {
        this.procInstId = procInstId;
    }

    /**
     * 返回 flowable流程实例ID
     *
     * @return
     */
    public String getProcInstId() {
        return procInstId;
    }

    public void setProcDefId(String procDefId) {
        this.procDefId = procDefId;
    }

    /**
     * 返回 flowable流程定义ID
     *
     * @return
     */
    public String getProcDefId() {
        return procDefId;
    }

    public void setBusinessKey(String businessKey) {
        this.businessKey = businessKey;
    }

    /**
     * 返回 businessKey
     *
     * @return
     */
    public String getBusinessKey() {
        return businessKey;
    }

    public Long getBusinessKeyNum() {
        return businessKeyNum;
    }

    public void setBusinessKeyNum(Long businessKeyNum) {
        this.businessKeyNum = businessKeyNum;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getBusinessUrl() {
        return businessUrl;
    }

    public void setBusinessUrl(String businessUrl) {
        this.businessUrl = businessUrl;
    }

    public String getPkName() {
        return pkName;
    }

    public void setPkName(String pkName) {
        this.pkName = pkName;
    }

    public Short getIsFormal() {
        return isFormal;
    }

    public void setIsFormal(Short isFormal) {
        this.isFormal = isFormal;
    }

    /**
     * @see Object#equals(Object)
     */
    @Override
    public boolean equals(Object object) {
        if (!(object instanceof ProcessRun)) {
            return false;
        }
        ProcessRun rhs = (ProcessRun) object;
        return new EqualsBuilder().append(this.runId, rhs.runId)
                .append(this.modelId, rhs.modelId)
                .append(this.subject, rhs.subject)
                .append(this.creatorId, rhs.creatorId)
                .append(this.creator, rhs.creator)
                .append(this.createTime, rhs.createTime)
                .append(this.busDescp, rhs.busDescp)
                .append(this.status, rhs.status)
                .append(this.procInstId, rhs.procInstId)
                .append(this.procDefId, rhs.procDefId)
                .append(this.businessKey, rhs.businessKey)
                .append(this.businessUrl, rhs.businessUrl).isEquals();
    }

    /**
     * @see Object#hashCode()
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder(-82280557, -700257973).append(this.runId)
                .append(this.modelId).append(this.subject).append(this.creatorId)
                .append(this.creator).append(this.createTime)
                .append(this.busDescp).append(this.status)
                .append(this.procInstId).append(this.procDefId)
                .append(this.businessKey).append(this.businessUrl).toHashCode();
    }

    /**
     * @see Object#toString()
     */
    @Override
    public String toString() {
        return new ToStringBuilder(this).append("runId", this.runId)
                .append("modelId", this.modelId)
                .append("subject", this.subject)
                .append("creatorId", this.creatorId)
                .append("creator", this.creator)
                .append("createTime", this.createTime)
                .append("endTime", this.endTime)
                .append("duration",this.duration)
                .append("busDescp", this.busDescp)
                .append("status", this.status)
                .append("procInstId", this.procInstId)
                .append("procDefId", this.procDefId)
                .append("businessKey", this.businessKey)
                .append("businessUrl", this.businessUrl).toString();
    }

    public String getProcessName() {
        return processName;
    }

    public void setProcessName(String processName) {
        this.processName = processName;
    }

    public Long getDuration() {
        return duration;
    }

    public void setDuration(Long duration) {
        this.duration = duration;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getStartOrgName() {
        return startOrgName;
    }

    public void setStartOrgName(String startOrgName) {
        this.startOrgName = startOrgName;
    }

    public String getStartOrgId() {
        return startOrgId;
    }

    public void setStartOrgId(String startOrgId) {
        this.startOrgId = startOrgId;
    }

    public Short getRecover() {
        return recover;
    }

    public void setRecover(Short recover) {
        this.recover = recover;
    }

    public String getDsAlias() {
        return dsAlias;
    }

    public void setDsAlias(String dsAlias) {
        this.dsAlias = dsAlias;
    }

    public static Short getStatusSuspend() {
        return STATUS_SUSPEND;
    }

    public static Short getStatusRunning() {
        return STATUS_RUNNING;
    }

    public static Short getStatusFinish() {
        return STATUS_FINISH;
    }

    public static Short getStatusManualFinish() {
        return STATUS_MANUAL_FINISH;
    }

    public static Short getStatusForm() {
        return STATUS_FORM;
    }

    public static Short getRecoverNo() {
        return RECOVER_NO;
    }

    @Override
    public Object clone() {
        ProcessRun obj = null;
        try {
            obj = (ProcessRun) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return obj;
    }

    public String getFormKeyUrl() {
        return formKeyUrl;
    }

    public void setFormKeyUrl(String formKeyUrl) {
        this.formKeyUrl = formKeyUrl;
    }

    public Short getFormType() {
        return formType;
    }

    public void setFormType(Short formType) {
        this.formType = formType;
    }


    public Long getLastSubmitDuration() {
        return lastSubmitDuration;
    }

    public void setLastSubmitDuration(Long lastSubmitDuration) {
        this.lastSubmitDuration = lastSubmitDuration;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }


    public String getTagIds() {
        return tagIds;
    }

    public void setTagIds(String tagIds) {
        this.tagIds = tagIds;
    }

    public String getOrgName() {
        return orgName;
    }

    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }

    public boolean isAllowBackToStart() {
        return allowBackToStart;
    }

    public void setAllowBackToStart(boolean allowBackToStart) {
        this.allowBackToStart = allowBackToStart;
    }

    public Integer getAllowFinishedDivert() {
        return allowFinishedDivert;
    }

    public void setAllowFinishedDivert(Integer allowFinishedDivert) {
        this.allowFinishedDivert = allowFinishedDivert;
    }


    public String getFlowKey() {
        return flowKey;
    }

    public void setFlowKey(String flowKey) {
        this.flowKey = flowKey;
    }

    public Short getIsPrintForm() {
        return isPrintForm;
    }

    public void setIsPrintForm(Short isPrintForm) {
        this.isPrintForm = isPrintForm;
    }

    public String getStartNode() {
        return startNode;
    }

    public void setStartNode(String startNode) {
        this.startNode = startNode;
    }


    public String getRelRunId() {
        if (relRunId == null) {
            return "";
        }
        return relRunId;
    }

    public void setRelRunId(String relRunId) {
        this.relRunId = relRunId;
    }

    public AuthorizeRight getAuthorizeRight() {
        return authorizeRight;
    }

    public void setAuthorizeRight(AuthorizeRight authorizeRight) {
        this.authorizeRight = authorizeRight;
    }

    public String getGlobalFlowNo() {
        return globalFlowNo;
    }

    public void setGlobalFlowNo(String globalFlowNo) {
        this.globalFlowNo = globalFlowNo;
    }

    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }


}
